# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=civetweb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.13
pkgrel=2
pkgdesc="Embedded C/C++ web server (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/civetweb/civetweb"
license=("MIT")
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/civetweb/civetweb/archive/v$pkgver.tar.gz")
sha256sums=('a7ccc76c2f1b5f4e8d855eb328ed542f8fe3b882a6da868781799a98f4acdedc')

build() {
    [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
    mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
    
    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        CFLAGS="-Wno-incompatible-pointer-types" \
        ${MINGW_PREFIX}/bin/cmake -G "MSYS Makefiles" \
        -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
        -DBUILD_SHARED_LIBS=YES \
        -DCIVETWEB_BUILD_TESTING=NO \
        -DCIVETWEB_ENABLE_WEBSOCKETS=YES \
        -DCIVETWEB_ENABLE_IPV6=YES \
        -DCIVETWEB_ENABLE_CXX=NO \
        -DCIVETWEB_ENABLE_SERVER_STATS=YES \
        -DCIVETWEB_SSL_OPENSSL_API_1_1=YES \
        -DCIVETWEB_ENABLE_SSL_DYNAMIC_LOADING=NO \
        -DLIBRT_LIBRARIES= \
        "${srcdir}/${_realname}-${pkgver}"
    make
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
    install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.md \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md"
    make DESTDIR=${pkgdir} install
}
